<?php
class lapkeuangancontroller extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('lapkeuangan_model');
	}

	function index(){

		if (isset($_POST['btnview']))
		{
			$pilih = trim($_POST['choose']);
			$tglawal = trim($_POST['tglawal']);
			$tglakhr = trim($_POST['tglakhir']);
			$transaksi  = trim($_POST['transaksi']);
		}else{
				
			$pilih = "";
			$tglawal = "";
			$tglakhr = "";
			$transaksi = "";
		}

		if ($transaksi == "J")
		{
			$data = $this->lapkeuangan_model->getMutasijual($tglawal,$tglakhr,$pilih);
		}else
		{
			$data = $this->lapkeuangan_model->getMutasibeli($tglawal,$tglakhr,$pilih);
		}
		//var_dump($_POST);exit;
		$dataprofile = array(
				'page_title' => 'Laporan > Keuangan',
				'name' => $this->session->userdata('fullname'),
				'data' => $data,
				'chosen' => $pilih,
				'trans' => $transaksi
		);
		$content = array(
		  'content' => 'laporan/lapkeuangan'
		  );
		  $this->template->load('templates/default',$content,$dataprofile);
	}

	function toExcel()
	{
		if ($_REQUEST['trans'] == "J")
		{
			$data = $this->lapkeuangan_model->getMutasijual($_REQUEST['tglAwal'],$_REQUEST['tglAkhir'],$_REQUEST['choosed']);
		}else
		{
			$data = $this->lapkeuangan_model->getMutasibeli($_REQUEST['tglAwal'],$_REQUEST['tglAkhir'],$_REQUEST['choosed']);
		}

		$dataprofile = array
		(
			'page_title' => '',
			'name' => '',
			'data' => $data
		);

		if ($_REQUEST['choosed'] == "C"){
			$this->load->view('laporan/excelkeuangan2',$dataprofile);
		}else{
			$this->load->view('laporan/excelkeuangan',$dataprofile);
		}
	}
}